import router from './router'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // getToken from cookie

NProgress.configure({
  showSpinner: false
}) // NProgress Configuration

router.beforeEach((to, from, next) => {
  NProgress.start()
  if (to.path !== '/login') {
    if (getToken()) {
      NProgress.done()
      next()
    } else {
      NProgress.done()
      next('/login')
    }
  } else {
    NProgress.done()
    // 登录页面,允许通过
    next()
  }
})
